﻿Public Class ListaPedidos
    Private binding1 As New BindingSource

    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
        Me.Dispose()
    End Sub

    Public Sub New()

        ' Llamada necesaria para el Diseñador de Windows Forms.
        InitializeComponent()

        ' Agregue cualquier inicialización después de la llamada a InitializeComponent().
        DGPedidos.DataSource = binding1
    End Sub

    Private Sub refrescarDataGrid()
        Dim sqlStr As String = New String("SELECT Fecha, Numero, Referencia, Clientes.Nombre AS Cliente, Fabricantes.Nombre AS Fabricante, Representantes.Nombre AS Representante " & _
                "FROM ((CabPedido INNER JOIN Clientes ON Clientes.NoCliente = CabPedido.Cliente) INNER JOIN Fabricantes ON Fabricantes.idFabricante = CabPedido.Fabricante) INNER JOIN Representantes ON Representantes.idRepresentante = CabPedido.Representante")
        Try
            binding1.DataSource = DataAccess.GetRecords(sqlStr, CommandType.Text)
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Sub

    Private Sub ListaPedidos_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        refrescarDataGrid()
    End Sub

    Private Sub DGPedidos_DataBindingComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) Handles DGPedidos.DataBindingComplete

        If e.ListChangedType = System.ComponentModel.ListChangedType.PropertyDescriptorChanged Then
            For Each c As DataGridViewTextBoxColumn In DGPedidos.Columns
                c.HeaderText = c.HeaderText.ToUpper()
            Next
        End If
    End Sub

End Class